<?php
	function Navigate($role,$navigate = NULL){
        if(is_array($role[0])){
            $role = i_array_column($role,'NAVIGATE');
        }

        $res = array();
        foreach ($navigate as $k => $v) {
        	if(is_array($v)){
        		$tmp_res = Navigate($role,$v);
        		if(!empty($tmp_res)) $res[$k] = $tmp_res;
        	}else{
        		if(in_array($k, $role)){
        			$res[$k] = $v;
        		}
        	}
        }
        return $res;
    }
    
    function HasAccess($url,$navigate = NULL){
        foreach ($navigate as $k => $v) {
            if(is_array($v)){
                $res = HasAccess($url,$v);
                if($res) return true;
            }else{
                if(in_array($url, $navigate)){
                    return true;
                }
            }
        }

        return false;
    }

    function i_array_column($input, $columnKey, $indexKey=null){
        if(!function_exists('array_column')){ 
            $columnKeyIsNumber  = (is_numeric($columnKey))?true:false; 
            $indexKeyIsNull            = (is_null($indexKey))?true :false; 
            $indexKeyIsNumber     = (is_numeric($indexKey))?true:false; 
            $result                         = array(); 
            foreach((array)$input as $key=>$row){ 
                if($columnKeyIsNumber){ 
                    $tmp= array_slice($row, $columnKey, 1); 
                    $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null; 
                }else{ 
                    $tmp= isset($row[$columnKey])?$row[$columnKey]:null; 
                } 
                if(!$indexKeyIsNull){ 
                    if($indexKeyIsNumber){ 
                      $key = array_slice($row, $indexKey, 1); 
                      $key = (is_array($key) && !empty($key))?current($key):null; 
                      $key = is_null($key)?0:$key; 
                    }else{ 
                      $key = isset($row[$indexKey])?$row[$indexKey]:0; 
                    } 
                } 
                $result[$key] = $tmp; 
            } 
            return $result; 
        }else{
            return array_column($input, $columnKey, $indexKey);
        }
    }

    /**
     * [MCache]
     * @Author   :seven
     * @DateTime :2016-12-02T16:41:27+0800
     * @Detail   :type for C 城市 | V 景点
     */
    function MCache($type = 'C',$vid){
        $data = array();
        switch ($type) {
            case 'C':
                $cs = Service('City','city','Admin');
                $data = $cs->query();
                break;
            case 'V':
                $vs = Service('View','view');
                $data = $vs->queryView();
                break;
            case 'A':
                $as = Service('Airport','airport','Admin');
                $data = $as->query();
                break;
            case 'D':
                $as = Service('DayTou','daytou','Admin');
                $data = $as->query();
                break;
            default:
                break;
        }
        return json_encode($data);
    }

    function Conf2Group($group){
        $data = include APP_PATH."/{$group}/Conf/navigation.php";
        return $data['NAVIGATE'];
    }
	?>